package com.neu.service.ww;

import com.neu.dao.ww.GoodsDao;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

public class GoodsService {
    private GoodsDao goodsDao;
    public GoodsService(){
        goodsDao=new GoodsDao();
    }
    public  List<Map<String,Object>> doFindByDate(){
        List<Map<String,Object>> list=null;
        LocalDate date=LocalDate.now();
        System.out.println(date.toString());
        try {
            list=goodsDao.findByDate(date.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public Map<String,Object> doFindById(String g_id){
        Map<String,Object> map=null;
        try {
            map=goodsDao.finfById(g_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
    public List<Map<String,Object>> doFindByLike(String text){
        List<Map<String,Object>> list=null;
        try {
            list=goodsDao.findByLike("%"+text+"%");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Map<String,Object>> doFindByKind(String text){
        List<Map<String,Object>> list=null;
        try {
            list=goodsDao.findByKind(text);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    public int doUpdateNumById(String g_id,String num){
        int row=0;
        try {
            //将num转为int类型
             int nums=Integer.parseInt(num);
            row=goodsDao.updateNumById(g_id,nums,g_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return row;
    }
    public Map<String,Object> doFindNumById(String g_id){
        Map<String,Object> map=null;
        try {
            map=goodsDao.findNumById(g_id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    public int doUpdateAllNumById(List<List<String>> lists) {
        int row=0;
        try {
            row=goodsDao.updateAllNumById(lists);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return row;
    }
}
